package com.ctshk.rpc.order.tour.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ctshk.rpc.order.tour.base.CustomBaseMapper;
import com.ctshk.rpc.order.tour.entity.SeriesOrderTouristFeeAdjust;
import com.ctshk.rpc.order.tour.vo.TouristCollectionFeeJson;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 谭响
 * @since 2021-01-22
 */
public interface SeriesOrderTouristFeeAdjustMapper extends CustomBaseMapper<SeriesOrderTouristFeeAdjust> {

    /**
     * 根据旅客清空旧数据
     * @param orderId
     * @param touristId
     * @param userId
     */
    @Update("UPDATE t_series_order_tourist_fee_adjust\n" +
            "SET is_deleted = 1,modified_id = #{modified_id}\n" +
            "WHERE order_id = #{order_id} AND tourist_id = #{tourist_id} AND is_deleted = 0")
    Integer cleanByTourist(@Param("order_id") Long orderId, @Param("tourist_id") Long touristId, @Param("modified_id") Long userId);

    /**
     * 获取旅客调整费用列表
     * @param touristId
     * @return
     */
    @Select("SELECT `name` AS projectName,amount AS totalAmount,plus_type AS adjustType\n" +
            "FROM t_series_order_tourist_fee_adjust\n" +
            "WHERE tourist_id = #{tourist_id} AND is_deleted = 0")
    List<TouristCollectionFeeJson> queryByTourist(@Param("tourist_id")Long touristId);


    @Select({
            "<script>",
            "SELECT ",
            "t.id,t.order_id,t.adjust_type,t.tourist_id,t.name,t.plus_type,t.amount,t.relation_id",
            "FROM t_series_order_tourist_fee_adjust t ",
            "WHERE t.is_deleted = 0 ",
            "AND order_id=#{orderid}",
            "<if test='touristIds != null and touristIds.size != 0 '>",
            "AND t.tourist_id IN ",
            "<foreach collection='touristIds' item='id' open='(' separator=',' close=')'>",
            "#{id}",
            "</foreach>",
            "</if> ",
            "</script>"
    })
    List<SeriesOrderTouristFeeAdjust> getOrderTouristFeeByAdjustIds(@Param("touristIds") List<Long> touristIds,@Param("orderid") Long orderid);
}
